<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'frontend.main.class.php');
$feObj = new FrontendMainBase();

//
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/gallery/gallery.category.class.php');
$mcObj = new GalleryCategoryBase();
$mcObj->format = true;
//
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/gallery/gallery.album.class.php');
$maObj = new GalleryAlbumBase();
$maObj->format = true;
//
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/gallery/gallery.image.class.php');
$mObj = new GalleryImageBase();
$mObj->format = true;

//
if( $request_link_class == 'c' ) {//category
	$category = $mcObj->getCategory($request_link_subclass, 'link');
	$albums = $maObj->getItems(array('cid:=' => $category['categories_id']));
	
	$feObj->content_wrap['mainpart'] = 'category';
	$feObj->content_wrap['category'] = $category;
	$feObj->content_wrap['albums'] = $albums;
} elseif( $request_link_class == 'a' ) {//album
	$album = $maObj->getItem($request_link_subclass, 'link');
	$items = $mObj->getItems(array('aid:=' => $album['id']), 0, false);
	
	$feObj->content_wrap['mainpart'] = 'category';
	$feObj->content_wrap['album'] = $album;
	$feObj->content_wrap['items'] = $items;
} elseif( $request_link_class > 0 ) {//image
	$item = $mObj->getItem($request_link_class, 'id');
	$items = $mObj->getItems(array('aid:=' => $item['aid']), 0, false);
	
	$feObj->content_wrap['mainpart'] = 'image';
	$feObj->content_wrap['item'] = $item;
	$feObj->content_wrap['items'] = $items;
} else {
	/*
	//album
	$albums = $maObj->getItems('', 0, false);
	for($i=0, $n=sizeof($albums); $i<$n; $i++) {
		$items = $mObj->getItems(array('aid:=' => $albums[$i]['id']), 0, false);
		$albums[$i]['item'] = $items['0'];
	}
	$feObj->content_wrap['albums'] = $albums;
	*/
	
	/*
	//list
	$items = $mObj->getItems('', 0, false);
	$feObj->content_wrap['mainpart'] = 'category';
	$feObj->content_wrap['items'] = $items;
	*/
	
	//image
	$items = $mObj->getItems('', 0, false);
	$feObj->content_wrap['mainpart'] = 'image';
	$feObj->content_wrap['items'] = $items;
	$feObj->content_wrap['item'] = $items['0'];
}

//
$feObj->addJsFile('slider.js');
echo $feObj->display('pagelayout/pagelayout_main_gallery.tpl');
//
?>